/*     */ package com.zimbra.cs.mailbox.acl;
/*     */ 
/*     */ import com.google.common.collect.ImmutableSet;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.mailbox.ACL;
/*     */ import com.zimbra.cs.mailbox.ACL.Grant;
/*     */ import com.zimbra.cs.mailbox.Document;
/*     */ import com.zimbra.cs.mailbox.Folder;
/*     */ import com.zimbra.cs.mailbox.MailItem;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.MailboxListener;
/*     */ import com.zimbra.cs.mailbox.MailboxListener.ChangeNotification;
/*     */ import com.zimbra.cs.mailbox.MailboxOperation;
/*     */ import com.zimbra.cs.mailbox.ScheduledTask;
/*     */ import com.zimbra.cs.mailbox.ScheduledTaskManager;
/*     */ import com.zimbra.cs.session.PendingModifications;
/*     */ import com.zimbra.cs.session.PendingModifications.Change;
/*     */ import java.util.Date;
/*     */ import java.util.LinkedHashMap;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ShareExpirationListener
/*     */   extends MailboxListener
/*     */ {
/*  42 */   private static final ImmutableSet<MailItem.Type> registeredTypes = ImmutableSet.of(MailItem.Type.FOLDER, MailItem.Type.DOCUMENT);
/*     */   
/*     */ 
/*     */ 
/*     */   public Set<MailItem.Type> registerForItemTypes()
/*     */   {
/*  48 */     return registeredTypes;
/*     */   }
/*     */   
/*     */   public void notify(MailboxListener.ChangeNotification notification)
/*     */   {
/*  53 */     if (notification.op == MailboxOperation.ExpireAccess) {
/*  54 */       return;
/*     */     }
/*  56 */     if (notification.mods.created != null) {
/*  57 */       for (MailItem created : notification.mods.created.values()) {
/*  58 */         if ((((created instanceof Folder)) || ((created instanceof Document))) && 
/*  59 */           (created.getACL() != null)) {
/*  60 */           scheduleExpireAccessOpIfReq(created);
/*     */         }
/*     */       }
/*     */     }
/*     */     
/*  65 */     if (notification.mods.modified != null) {
/*  66 */       for (PendingModifications.Change change : notification.mods.modified.values()) {
/*  67 */         if ((((change.what instanceof Folder)) || ((change.what instanceof Document))) && ((change.why & 0x200000) != 0))
/*     */         {
/*  69 */           scheduleExpireAccessOpIfReq((MailItem)change.what);
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   static void scheduleExpireAccessOpIfReq(MailItem item)
/*     */   {
/*     */     try {
/*  78 */       ExpireGrantsTask.cancel(item.getMailboxId(), item.getId());
/*     */     } catch (ServiceException e) {
/*  80 */       ZimbraLog.scheduler.warn("Error in canceling existing ExpireGrantsTask for (id=%s,mailboxId=%s)", Integer.valueOf(item.getId()), Integer.valueOf(item.getMailboxId()), e);
/*     */       
/*  82 */       return;
/*     */     }
/*  84 */     ACL acl = item.getACL();
/*  85 */     if (acl == null) {
/*  86 */       return;
/*     */     }
/*  88 */     long nextExpiry = 0L;
/*  89 */     for (ACL.Grant grant : acl.getGrants()) {
/*  90 */       long expiry = grant.getEffectiveExpiry(acl);
/*  91 */       if (expiry != 0L) {
/*  92 */         nextExpiry = expiry < nextExpiry ? expiry : nextExpiry == 0L ? expiry : nextExpiry;
/*     */       }
/*     */     }
/*  95 */     if (nextExpiry == 0L)
/*     */     {
/*  97 */       return;
/*     */     }
/*  99 */     ScheduledTask task = new ExpireGrantsTask();
/* 100 */     task.setMailboxId(item.getMailboxId());
/*     */     
/* 102 */     task.setExecTime(new Date(nextExpiry + 60000L));
/* 103 */     task.setProperty("itemId", Integer.toString(item.getId()));
/*     */     try {
/* 105 */       ScheduledTaskManager.schedule(task);
/*     */     } catch (ServiceException e) {
/* 107 */       ZimbraLog.scheduler.warn("Error in scheduling task %s", task.toString(), e);
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/acl/ShareExpirationListener.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */